#! /bin/bash
set -e


if [ $# -ne 1 ]; then
    echo  usage: $0 "<path-of-installation-folder>"
    exit 1
fi

INSTALL_FOLDER=$1
echo $INSTALL_FOLDER
cd gvirtus
#make clean
./autogen.sh --prefix="${INSTALL_FOLDER}"
make
make install
cd ..
cd gvirtus.cudart
#make clean
./autogen.sh --prefix="${INSTALL_FOLDER}"
make
make install
cd ..
cd gvirtus.cudadr
#make clean
./autogen.sh --prefix="${INSTALL_FOLDER}"
make
make install

cd ..
cd gvirtus.cufft
#make clean
./autogen.sh --prefix="${INSTALL_FOLDER}"
make
make install
cd ..

cd gvirtus.cublas
#make clean
./autogen.sh --prefix="${INSTALL_FOLDER}"
make
make install
cd ..

cd gvirtus.curand
#make clean
./autogen.sh --prefix="${INSTALL_FOLDER}"
make
make install
cd ..

#cd gvirtus.cudnn
#make clean
#./autogen.sh --prefix="${INSTALL_FOLDER}"
#make
#make install

cd $INSTALL_FOLDER/lib/frontend
ln -sf libcudart.so.6.5.14 libcudart.so.6.5
ln -sf libcudart.so.6.5.14 libcudart.so.8.0
ln -sf libcublas.so.8.0.0 libcublas.so.6.5
ln -sf libcufft.so libcufft.so.6.5
ln -sf libcurand.so libcurand.so.6.5
ln -sf libcufft.so.3.0.0 libcufft.so.8.0
ln -sf libcudart.so libcudart.so.9.0
ln -sf libcuda.so libcuda.so.9.0
ln -sf libcublas.so libcublas.so.9.0
ln -sf libcufft.so libcufft.so.9.0

echo
echo
echo INSTALLATION COMPLETED!
